package me.w70.bot.util;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.table.DefaultTableModel;
import javax.swing.tree.DefaultMutableTreeNode;

import org.jdesktop.layout.GroupLayout;
import org.jdesktop.layout.LayoutStyle;

public class DebugInterfacesUI extends JFrame {
	private DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Root");

	public DebugInterfacesUI() {
		initComponents();
	}

	private void filterTextMenuItemActionPerformed() {
		searchTextField.setText("");
		filterByTextFrame.setVisible(true);
	}

	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY
		// //GEN-BEGIN:initComponents
		menuBar1 = new JMenuBar();
		menu1 = new JMenu();
		filterTextMenuItem = new JMenuItem();
		separator1 = new JPopupMenu.Separator();
		updateButton = new JButton();
		scrollPane1 = new JScrollPane();
		interfaceTree = new JTree(rootNode);
		scrollPane2 = new JScrollPane();
		infoTable = new JTable();
		filterByTextFrame = new JFrame();
		searchTextField = new JTextField();
		searchTextButton = new JButton();

		// ======== this ========
		setTitle("Interface debugger");
		Container contentPane = getContentPane();

		// ======== menuBar1 ========
		{

			// ======== menu1 ========
			{
				menu1.setText("Filter");

				// ---- filterTextMenuItem ----
				filterTextMenuItem.setText("Filter by text");
				filterTextMenuItem.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						filterTextMenuItemActionPerformed();
					}
				});
				menu1.add(filterTextMenuItem);
			}
			menuBar1.add(menu1);
			menuBar1.add(separator1);

			// ---- updateButton ----
			updateButton.setText("Update");
			menuBar1.add(updateButton);
		}
		setJMenuBar(menuBar1);

		// ======== scrollPane1 ========
		{
			scrollPane1.setViewportView(interfaceTree);
		}

		// ======== scrollPane2 ========
		{

			// ---- infoTable ----
			infoTable.setModel(new DefaultTableModel(new Object[][] { { null },
					{ null }, }, new String[] { "Interface information" }) {
				Class[] columnTypes = new Class[] { String.class };

				boolean[] columnEditable = new boolean[] { false };

				@Override
				public Class<?> getColumnClass(int columnIndex) {
					return columnTypes[columnIndex];
				}

				@Override
				public boolean isCellEditable(int rowIndex, int columnIndex) {
					return columnEditable[columnIndex];
				}
			});
			scrollPane2.setViewportView(infoTable);
		}

		GroupLayout contentPaneLayout = new GroupLayout(contentPane);
		contentPane.setLayout(contentPaneLayout);
		contentPaneLayout
				.setHorizontalGroup(contentPaneLayout
						.createParallelGroup()
						.add(
								contentPaneLayout
										.createSequentialGroup()
										.addContainerGap()
										.add(scrollPane1,
												GroupLayout.PREFERRED_SIZE,
												197, GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(LayoutStyle.RELATED)
										.add(scrollPane2,
												GroupLayout.DEFAULT_SIZE, 229,
												Short.MAX_VALUE)
										.addContainerGap()));
		contentPaneLayout
				.setVerticalGroup(contentPaneLayout
						.createParallelGroup()
						.add(
								GroupLayout.TRAILING,
								contentPaneLayout
										.createSequentialGroup()
										.addContainerGap()
										.add(
												contentPaneLayout
														.createParallelGroup(
																GroupLayout.TRAILING)
														.add(
																GroupLayout.LEADING,
																scrollPane2,
																GroupLayout.DEFAULT_SIZE,
																362,
																Short.MAX_VALUE)
														.add(
																GroupLayout.LEADING,
																scrollPane1))
										.addContainerGap()));
		pack();
		setLocationRelativeTo(getOwner());

		// ======== filterByTextFrame ========
		{
			filterByTextFrame.setTitle("Filter by text");
			Container filterByTextFrameContentPane = filterByTextFrame
					.getContentPane();

			// ---- searchTextButton ----
			searchTextButton.setText("Search");

			GroupLayout filterByTextFrameContentPaneLayout = new GroupLayout(
					filterByTextFrameContentPane);
			filterByTextFrameContentPane
					.setLayout(filterByTextFrameContentPaneLayout);
			filterByTextFrameContentPaneLayout
					.setHorizontalGroup(filterByTextFrameContentPaneLayout
							.createParallelGroup().add(
									filterByTextFrameContentPaneLayout
											.createSequentialGroup()
											.addContainerGap().add(
													searchTextField,
													GroupLayout.DEFAULT_SIZE,
													244, Short.MAX_VALUE)
											.addPreferredGap(
													LayoutStyle.RELATED).add(
													searchTextButton)
											.addContainerGap()));
			filterByTextFrameContentPaneLayout
					.setVerticalGroup(filterByTextFrameContentPaneLayout
							.createParallelGroup()
							.add(
									filterByTextFrameContentPaneLayout
											.createSequentialGroup()
											.addContainerGap()
											.add(
													filterByTextFrameContentPaneLayout
															.createParallelGroup(
																	GroupLayout.BASELINE)
															.add(
																	searchTextField,
																	GroupLayout.PREFERRED_SIZE,
																	GroupLayout.DEFAULT_SIZE,
																	GroupLayout.PREFERRED_SIZE)
															.add(
																	searchTextButton))
											.addContainerGap(10,
													Short.MAX_VALUE)));
			filterByTextFrame.pack();
			filterByTextFrame.setLocationRelativeTo(filterByTextFrame
					.getOwner());
		}
		// JFormDesigner - End of component initialization
		// //GEN-END:initComponents
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY
	// //GEN-BEGIN:variables
	private JMenuBar menuBar1;

	private JMenu menu1;

	private JMenuItem filterTextMenuItem;

	private JPopupMenu.Separator separator1;

	public JButton updateButton;

	private JScrollPane scrollPane1;

	public JTree interfaceTree;

	private JScrollPane scrollPane2;

	public JTable infoTable;

	public JFrame filterByTextFrame;

	public JTextField searchTextField;

	public JButton searchTextButton;
	// JFormDesigner - End of variables declaration //GEN-END:variables
}
